package cn.jarlen.jwt.tools.menu;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.widget.Toast;

import cn.jarlen.jwt.tools.device.DeviceUtils;
import cn.jarlen.jwt.tools.utils.LittleUtils;

/**
 * @author jarlen
 * Create by 2023/4/12 13:19
 */
public class IMEIRead implements IMenuProcess {

    @Override
    public void onExecute(Context context) {
        String imeiFromAndroidApi = DeviceUtils.getIMEIByAndroidApi(context);
        String imeiByDevicePolicy = DeviceUtils.getImeiByDevicePolicyManager();
        String imeiByDingQiaoPolicy = DeviceUtils.getImeiByDingQiaoPolicyManager(context);

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("【查询IMEI】").append("\n");
        stringBuilder.append("原生:").append(LittleUtils.checkEmpty(imeiFromAndroidApi)).append("\n");
        stringBuilder.append("JW部标:").append(LittleUtils.checkEmpty(imeiByDevicePolicy)).append("\n");
        stringBuilder.append("鼎桥OS:").append(LittleUtils.checkEmpty(imeiByDingQiaoPolicy));

        Toast.makeText(context, stringBuilder, Toast.LENGTH_LONG).show();
        getIMEI(context);
    }

    private static String getIMEI(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            return null;
        }
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyManager == null) {
                return null;
            }
            String imei = telephonyManager.getDeviceId();
            return imei;
        } catch (Exception e) {
            return null;
        }
    }
}
